
const baseUrl = 'http://127.0.0.1:8051/' ;

export const myAjaxPost = function(url,data,cbSuccess){
	let  cfg ={		     
		     url: baseUrl+url ,
		     type:'POST',
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             data:JSON.stringify(data),
             beforeSend: function(xhr) {
                  xhr.setRequestHeader('Authorization', sessionStorage.getItem('Authorization')); 
             },
             success:function(res){ajaxSuccess(res,cbSuccess)},
             error:ajaxError 
	      };
	 
	 $.ajax(cfg);
}

const ajaxSuccess = function(res,cbSuccess){
	if(res.code=="200" || res.code=="210"){
		cbSuccess(res);
	}else if(res.code=="611"){
		xAlert.error("token 失效，请重新登录");
	}else{
		xAlert.error("网络错误或请求失败，请刷新后重试");
	}
	
}

const ajaxError = function(res){
	xAlert.error("网络错误或请求失败，请刷新后重试");
}